package com.xinchuang.service.actual.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.xinchuang.comment.KeyWord;
import com.xinchuang.comment.R;
import com.xinchuang.domain.entity.*;
import com.xinchuang.domain.pojo.*;
import com.xinchuang.domain.type.NoticeMainEnum;
import com.xinchuang.entity.EdtionNotice;
import com.xinchuang.entity.api.OaUserParam;
import com.xinchuang.entity.api.UserApi;
import com.xinchuang.manager.TestImageService;
import com.xinchuang.mapper.*;
import com.xinchuang.role.entity.SystemHeader;
import com.xinchuang.service.OaUserService;
import com.xinchuang.service.actual.EdtionNoticeService;
import com.xinchuang.service.actual.TestNoticeConsumableTableService;
import com.xinchuang.service.actual.TestNoticeTimeService;
import com.xinchuang.service.actual.TestNoticeTimeTableService;
import com.xinchuang.utils.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zx
 * @since 2023-07-04
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class TestNoticeTimeTableServiceImpl extends ServiceImpl<TestNoticeTimeTableMapper, TestNoticeTimeTable> implements TestNoticeTimeTableService {

    private final TestModelSubTableMapper testModelSubTableMapper;

    private final TestNoticeMainTabaleMapper testNoticeMainTabaleMapper;

    private final TestNoticeTimeTableMapper testNoticeTimeTableMapper;

    private final TestNoticeExceptionTimeTableMapper testNoticeExceptionTimeTableMapper;

    private final TestNoticeProductionTypeTableMapper testNoticeProductionTypeTableMapper;

    private final TestNoticeConsumableTableMapper testNoticeConsumableTableMapper;

    private final TestNoticeConsumableTableService testNoticeConsumableTableService;

    private final TestNoticeProductionProcessTableMapper testNoticeProductionProcessTableMapper;

    private final TestModelParamMapper modelParamMapper;

    private final DictTableMapper dictTableMapper;

    private final TestNoticeTimeService testNoticeTimeService;

    private final TestNoticeTimeMapper testNoticeTimeMapper;

    private final EdtionNoticeService edtionNoticeService;

    private final UserApiMapper userApiMapper;

    private final OaUserService oaUserService;
    private final TestImageService testImageService;
    private final TestImageMapper testImageMapper;
    private final KeyWord keyWord;
    private final TryOutDeviceModMapper tryOutDeviceModMapper;

    @Override
    public String getTryOutReport(JSONObject jsonObject) {
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        TestNoticeMainTabale mainTabale = testNoticeMainTabaleMapper.selectById(noteId);
        if (ObjectUtil.isNotNull(mainTabale)) {
            //审批验证
            if (MyUtils.verifyNotice(1, mainTabale.getStatus())) {
                return JSON.toJSONString(R.fail(500, NoticeMainEnum.getMessage(mainTabale.getStatus())));
            }
            TestModelSubTable subTable = testModelSubTableMapper.selectById(mainTabale.getParentPlanSubId());
            TestModelParam modelParam = modelParamMapper.selectById(subTable.getMoldId());
            JSONObject json = new JSONObject();
            //头部
            json.put("reportName", StringUtils.isNotBlank(mainTabale.getReportName()) ? mainTabale.getReportName() : "试模报告");
            json.put("serialNumber", mainTabale.getSerialNumber());
            json.put("versionId", mainTabale.getTestVersionId());
            //json.put("tryOutDate", ObjectUtil.isNull(subTable) ? "" : ObjectUtil.isNull(subTable.getPracticalTime()) ? "" : DateUtil.format(subTable.getPracticalTime(), "yyyy-MM-dd"));
            json.put("projectName", StringUtils.isBlank(subTable.getProjectName()) ? ObjectUtil.isNotNull(modelParam) && StringUtils.isNotBlank(modelParam.getProjectName()) ? modelParam.getProjectName() : "" : subTable.getProjectName());
            json.put("moldId", ObjectUtil.isNull(subTable) ? "" : subTable.getMoldId());
            json.put("tryOutDeviceId", mainTabale.getTryOutDeviceId());
            json.put("tryOutTimes", ObjectUtil.isNull(subTable) ? "" : StringUtils.isNotEmpty(subTable.getTryOutTimes()) ? "T" + subTable.getTryOutTimes() : "");
            json.put("tryOutTypeId", mainTabale.getTryOutTypeId());
            json.put("tryOutCompanyId", mainTabale.getTryOutCompanyId());
            String tryOutEngineer = "";
            if (StringUtils.isNotBlank(mainTabale.getTongmanName())) {
                UserApi userApi = userApiMapper.selectById(mainTabale.getTongmanName());
                if (ObjectUtil.isNotNull(userApi)) {
                    tryOutEngineer = userApi.getName();
                }
            }
            json.put("tryOutEngineer", tryOutEngineer);
            json.put("projectManager", MyUtils.getString(mainTabale.getProjectManager()));
            json.put("targetId", MyUtils.getString(mainTabale.getTargetId()));
            //试模用时记录
            TestNoticeTimeTable timeTable = testNoticeTimeTableMapper.selectOne(
                    new QueryWrapper<TestNoticeTimeTable>()
                            .lambda()
                            .eq(TestNoticeTimeTable::getParentNoticeId, noteId)
                            .last("LIMIT 1")
            );

            List<TestNoticeTime> noticeTimeList = testNoticeTimeService.list(new LambdaQueryWrapper<TestNoticeTime>()
                    .eq(TestNoticeTime::getParentNoticeId, noteId)
                    .eq(TestNoticeTime::getStatus, 1)
                    .orderByAsc(TestNoticeTime::getSort));
            if (Objects.nonNull(noticeTimeList) && !noticeTimeList.isEmpty()) {
                LocalDateTime startTime = noticeTimeList.get(0).getStartTime();
                DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                json.put("tryOutDate", startTime.format(sdf));
            } else {
                json.put("tryOutDate", "");
            }
            long load = testNoticeTimeMapper.getSumTime(noteId, 1);
            long wait = testNoticeTimeMapper.getSumTime(noteId, 2);
            long demoProduce = testNoticeTimeMapper.getSumTime(noteId, 3);
            long unload = testNoticeTimeMapper.getSumTime(noteId, 4);
            long breakdown = testNoticeTimeMapper.getSumTime(noteId, 5);
            long fix = testNoticeTimeMapper.getSumTime(noteId, 6);
            long debug = testNoticeTimeMapper.getSumTime(noteId, 7);
            json.put("loadTime", MyUtils.getTime(load));
            json.put("waitTime", MyUtils.getTime(wait));
            json.put("breakdownTime", MyUtils.getTime(breakdown));
            json.put("fixTime", MyUtils.getTime(fix));
            json.put("debugTime", MyUtils.getTime(debug));
            json.put("demoProduceTime", MyUtils.getTime(demoProduce));
            json.put("unloaTime", MyUtils.getTime(unload));
            json.put("totalTime", MyUtils.getTime(load + wait + demoProduce + unload + breakdown + fix + debug));
            json.put("costTimeRemark", ObjectUtil.isNull(timeTable) ? "" : timeTable.getRemark());
            //二、异常时间记录
            List<TestNoticeExceptionTimeTable> testNoticeExceptionTimeTables = testNoticeExceptionTimeTableMapper.selectList(
                    new QueryWrapper<TestNoticeExceptionTimeTable>()
                            .lambda()
                            .eq(TestNoticeExceptionTimeTable::getParentNoticeId, noteId)
            );
            JSONArray array = new JSONArray();
            if (CollectionUtil.isNotEmpty(testNoticeExceptionTimeTables)) {
                JSONObject exception;
                for (TestNoticeExceptionTimeTable exceptionTimeTable : testNoticeExceptionTimeTables) {
                    exception = new JSONObject();
                    exception.put("exceptionId", exceptionTimeTable.getExceptionId());
                    exception.put("exceptionPeriod", ObjectUtil.isNull(exceptionTimeTable) ? "" : exceptionTimeTable.getTimeFrame());
                    exception.put("exceptionHour", ObjectUtil.isNull(exceptionTimeTable) ? "" : exceptionTimeTable.getTimes());
                    exception.put("waitDetailContent", ObjectUtil.isNull(exceptionTimeTable) ? "" : exceptionTimeTable.getWaitContent());
                    exception.put("fixDetialContent", ObjectUtil.isNull(exceptionTimeTable) ? "" : exceptionTimeTable.getRepairContent());
                    exception.put("breakdownDetialContent", ObjectUtil.isNull(exceptionTimeTable) ? "" : exceptionTimeTable.getFaultContent());
                    exception.put("exceptionRemark", ObjectUtil.isNull(exceptionTimeTable) ? "" : exceptionTimeTable.getRemark());
                    array.add(exception);
                }
            } else {
                JSONObject exception = new JSONObject();
                exception.put("exceptionId", "");
                exception.put("exceptionPeriod", "");
                exception.put("exceptionHour", "");
                exception.put("waitDetailContent", "");
                exception.put("fixDetialContent", "");
                exception.put("breakdownDetialContent", "");
                exception.put("exceptionRemark", "");
                array.add(exception);
            }
            json.put("exceptionDataList", array);
            //三、调试及样件生产状态
            TestNoticeProductionTypeTable productionTypeTable = testNoticeProductionTypeTableMapper.selectOne(
                    new QueryWrapper<TestNoticeProductionTypeTable>()
                            .lambda()
                            .eq(TestNoticeProductionTypeTable::getParentNoticeId, noteId)
                            .last("LIMIT 1")
            );
            json.put("debugMoldCount", ObjectUtil.isNull(productionTypeTable) ? "" : productionTypeTable.getModulusQuantity());
            json.put("produceMoldCount", ObjectUtil.isNull(productionTypeTable) ? "" : productionTypeTable.getProductionQuantity());
            json.put("qualifiedMoldCount", ObjectUtil.isNull(productionTypeTable) ? "" : productionTypeTable.getQualifiedQuantity());
            json.put("concessionalReceivingCount", ObjectUtil.isNull(productionTypeTable) ? "" : productionTypeTable.getReceiveQuantity());
            json.put("perCount", ObjectUtil.isNull(productionTypeTable) ? "" : productionTypeTable.getMoldNumber());
            json.put("moldWeight", ObjectUtil.isNull(productionTypeTable) ? "" : productionTypeTable.getModelWeight());
            json.put("productionTakt", ObjectUtil.isNull(productionTypeTable) ? "" : productionTypeTable.getProductionBeat());
            //四、消耗材料
            List<TestNoticeConsumableTable> testNoticeConsumableTableList = testNoticeConsumableTableMapper.selectList(
                    new QueryWrapper<TestNoticeConsumableTable>().lambda()
                            .eq(TestNoticeConsumableTable::getParentNoticeId, noteId).orderByAsc(TestNoticeConsumableTable::getConsumptionId));
            json.put("consumableInfo", testNoticeConsumableTableList);
           /* TestNoticeConsumableTable material = testNoticeConsumableTableMapper.selectOne(
                    new QueryWrapper<TestNoticeConsumableTable>()
                            .lambda()
                            .eq(TestNoticeConsumableTable::getParentNoticeId, noteId)
                            .eq(TestNoticeConsumableTable::getType, "1")
                            .last("LIMIT 1")
            );
            json.put("materialSpec", ObjectUtil.isNull(material) ? "" : material.getSpecification());
            json.put("materialReceiveCount", ObjectUtil.isNull(material) ? "" : material.getClaim());
            json.put("materialReturnCount", ObjectUtil.isNull(material) ? "" : material.getStock());
            json.put("materialConsumeCount", ObjectUtil.isNull(material) ? "" : material.getConsumption());
            json.put("materialExceptionCount", ObjectUtil.isNull(material) ? "" : material.getDescription());

            TestNoticeConsumableTable carton = testNoticeConsumableTableMapper.selectOne(
                    new QueryWrapper<TestNoticeConsumableTable>()
                            .lambda()
                            .eq(TestNoticeConsumableTable::getParentNoticeId, noteId)
                            .eq(TestNoticeConsumableTable::getType, "2")
                            .last("LIMIT 1")
            );
            json.put("cartonSpec", ObjectUtil.isNull(carton) ? "" : carton.getSpecification());
            json.put("cartonReceiveCount", ObjectUtil.isNull(carton) ? "" : carton.getClaim());
            json.put("cartonReturnCount", ObjectUtil.isNull(carton) ? "" : carton.getStock());
            json.put("cartonConsumeCount", ObjectUtil.isNull(carton) ? "" : carton.getConsumption());
            json.put("cartonExceptionCount", ObjectUtil.isNull(carton) ? "" : carton.getDescription());

            TestNoticeConsumableTable packingbag = testNoticeConsumableTableMapper.selectOne(
                    new QueryWrapper<TestNoticeConsumableTable>()
                            .lambda()
                            .eq(TestNoticeConsumableTable::getParentNoticeId, noteId)
                            .eq(TestNoticeConsumableTable::getType, "3")
                            .last("LIMIT 1")
            );
            json.put("packingbagSpec", ObjectUtil.isNull(packingbag) ? "" : packingbag.getSpecification());
            json.put("packingbagReceiveCount", ObjectUtil.isNull(packingbag) ? "" : packingbag.getClaim());
            json.put("packingbagReturnCount", ObjectUtil.isNull(packingbag) ? "" : packingbag.getStock());
            json.put("packingbagConsumeCount", ObjectUtil.isNull(packingbag) ? "" : packingbag.getConsumption());
            json.put("packingbagExceptionCount", ObjectUtil.isNull(packingbag) ? "" : packingbag.getDescription());*/
            //五、产品工艺参数
            TestNoticeProductionProcessTable productionProcessTable = testNoticeProductionProcessTableMapper.selectOne(
                    new QueryWrapper<TestNoticeProductionProcessTable>()
                            .lambda()
                            .eq(TestNoticeProductionProcessTable::getParentNoticeId, noteId)
                            .last("LIMIT 1")
            );
            json.put("materialName", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getMaterialName());
            json.put("dryingTemperature", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getBakingTemperature());
            json.put("dryingTime", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getBakingTime());
            json.put("storageEndPoint", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getEndPosition());
            json.put("dwellTime", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getHoldingTime());
            json.put("dwellPressure", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getHoldingPressure());
            json.put("dwellSpeed", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getHoldingSpeed());
            json.put("collingTime", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getCoolingTime());
            if (ObjectUtil.isNull(productionProcessTable)) {
                json.put("ejectionEjectionParams", MyUtils.ejectionEjectionParams());
            } else {
                JSONArray jsonArray = MyUtils.getJSONArray(productionProcessTable.getSprue());
                if (CollectionUtil.isEmpty(jsonArray)) {
                    json.put("ejectionEjectionParams", MyUtils.ejectionEjectionParams());
                } else {
                    json.put("ejectionEjectionParams", jsonArray);
                }
            }
            if (ObjectUtil.isNull(productionProcessTable)) {
                json.put("screwTemperature", MyUtils.screwTemperature());
            } else {
                JSONArray jsonArray = MyUtils.getJSONArray(productionProcessTable.getScrewTemperature());
                if (CollectionUtil.isEmpty(jsonArray)) {
                    json.put("screwTemperature", MyUtils.screwTemperature());
                } else {
                    json.put("screwTemperature", jsonArray);
                }
            }
            json.put("moldTemperature", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getMoldTemperature());
            json.put("hotRunnerTemperature", ObjectUtil.isNull(productionProcessTable) ? "" : productionProcessTable.getHeatedTemperature());
            if (ObjectUtil.isNull(productionProcessTable)) {
                json.put("sequentialValveFeedingMode", MyUtils.sequentialValveFeedingMode());
            } else {
                JSONArray jsonArray = MyUtils.getJSONArray(productionProcessTable.getSprueFeedingMethod());
                if (CollectionUtil.isEmpty(jsonArray)) {
                    json.put("sequentialValveFeedingMode", MyUtils.sequentialValveFeedingMode());
                } else {
                    json.put("sequentialValveFeedingMode", jsonArray);
                }
            }
            // json.put("image", ObjectUtil.isNull(productionProcessTable) ? "" : MyUtils.getString(productionProcessTable.getImage()));
            //查询图片信息
            if (Objects.nonNull(productionProcessTable)) {
                List<TestImage> testImageList = testImageMapper.selectList(new LambdaQueryWrapper<TestImage>()
                        .eq(TestImage::getType, 1)
                        .eq(TestImage::getSceneId, productionProcessTable.getProductionId())
                        .orderByAsc(TestImage::getCreateTime));
                json.put("image", testImageList.stream().map(x -> x.getUrl()).collect(Collectors.toList()));
            } else {
                json.put("image", "");
            }
            return JSON.toJSONString(R.data(json));
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String exportTryOutReport(JSONObject jsonObject, HttpServletResponse response) {
        String resultPath = "";
        try {
            String rootUrl = keyWord.getFileUrl();
            R r = JSON.parseObject(this.getTryOutReport(jsonObject), R.class);
            JSONObject jsonObjectData = JSON.parseObject(JSON.toJSONString(r.getData()));
            String projectName = jsonObjectData.getString("projectName");
            String fileName = projectName + "项目-试模报告单-" + DateUtils.dateTimeNow("yyyyMMdd-SSS");
            resultPath = "file" + File.separator + fileName + ".xlsx";
            String filePath = rootUrl + File.separator + resultPath;
            //在内存中创建一个Excel文件对象
            XSSFWorkbook workbook = new XSSFWorkbook();
            String sheetName = projectName + "项目-试模报告单";
            //创建Sheet页
            XSSFSheet sheet = workbook.createSheet(sheetName);

            String versionId = jsonObjectData.getString("versionId");
            if (StringUtils.isNotBlank(versionId)) {
                DictTable dictTable = dictTableMapper.selectById(versionId);
                versionId = Objects.nonNull(dictTable) ? dictTable.getDicName() : "";
            }

            String tryOutTypeId = jsonObjectData.getString("tryOutTypeId");
            if (StringUtils.isNotBlank(tryOutTypeId)) {
                DictTable dictTable = dictTableMapper.selectById(tryOutTypeId);
                tryOutTypeId = Objects.nonNull(dictTable) ? dictTable.getDicName() : "";
            }

            String tryOutCompanyId = jsonObjectData.getString("tryOutCompanyId");
            if (StringUtils.isNotBlank(tryOutCompanyId)) {
                DictTable dictTable = dictTableMapper.selectById(tryOutCompanyId);
                tryOutCompanyId = Objects.nonNull(dictTable) ? dictTable.getDicName() : "";
            }

            String tryOutDeviceId = jsonObjectData.getString("tryOutDeviceId");
            if (StringUtils.isNotBlank(tryOutDeviceId)) {
                TryOutDeviceMod tryOutDeviceMod = tryOutDeviceModMapper.selectById(tryOutDeviceId);
                tryOutDeviceId = Objects.nonNull(tryOutDeviceMod) ? tryOutDeviceMod.getDeviceName() : "";
            }

            /**
             * 试模信息
             */
            int row = 0, col = 0;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue("名称");
            PoiUtils.mergedRegion(sheet, row, row, col + 1, col + 2, jsonObjectData.getString("reportName"));
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue("编号");
            PoiUtils.mergedRegion(sheet, row, row, col + 4, col + 5, jsonObjectData.getString("serialNumber"));
            PoiUtils.getRow(sheet, row).createCell(col + 6).setCellValue("版本");
            PoiUtils.mergedRegion(sheet, row, row, col + 7, col + 8, versionId);
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue("试模日期");
            PoiUtils.mergedRegion(sheet, row, row, col + 1, col + 2, jsonObjectData.getString("tryOutDate"));
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue("项目名称");
            PoiUtils.mergedRegion(sheet, row, row, col + 4, col + 5, projectName);
            PoiUtils.getRow(sheet, row).createCell(col + 6).setCellValue("模具编号");
            PoiUtils.mergedRegion(sheet, row, row, col + 7, col + 8, jsonObjectData.getString("moldId"));
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue("试模设备");
            PoiUtils.mergedRegion(sheet, row, row, col + 1, col + 2, tryOutDeviceId);
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue("试模次数");
            PoiUtils.mergedRegion(sheet, row, row, col + 4, col + 5, jsonObjectData.getString("tryOutTimes"));
            PoiUtils.getRow(sheet, row).createCell(col + 6).setCellValue("试模类型");
            PoiUtils.mergedRegion(sheet, row, row, col + 7, col + 8, tryOutTypeId);
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue("试模单位");
            PoiUtils.mergedRegion(sheet, row, row, col + 1, col + 2, tryOutCompanyId);
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue("试模调试工程师");
            PoiUtils.mergedRegion(sheet, row, row, col + 4, col + 5, jsonObjectData.getString("tryOutEngineer"));
            PoiUtils.getRow(sheet, row).createCell(col + 6).setCellValue("项目工程师");
            PoiUtils.mergedRegion(sheet, row, row, col + 7, col + 8, jsonObjectData.getString("projectManager"));
            row++;

            /**
             * 试模用时记录
             */
            //特殊背景颜色处理
            List<Integer> colorList = new ArrayList<>();
            colorList.add(row);
            PoiUtils.mergedRegion(sheet, row, row, col, col + 8, "一、试模用时记录（H）");
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue("上模等待用时（H）");
            PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue("等待总时数（H）");
            PoiUtils.getRow(sheet, row).createCell(col + 2).setCellValue("设备故障用时（H）");
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue("修模用时（H）");
            PoiUtils.getRow(sheet, row).createCell(col + 4).setCellValue("调试用时（H）");
            PoiUtils.getRow(sheet, row).createCell(col + 5).setCellValue("样件生产时间（H）");
            PoiUtils.getRow(sheet, row).createCell(col + 6).setCellValue("下模时间（H）");
            PoiUtils.getRow(sheet, row).createCell(col + 7).setCellValue("当天用时总数（H）");
            PoiUtils.getRow(sheet, row).createCell(col + 8).setCellValue("备注");
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue(jsonObjectData.getString("loadTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue(jsonObjectData.getString("waitTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 2).setCellValue(jsonObjectData.getString("breakdownTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue(jsonObjectData.getString("fixTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 4).setCellValue(jsonObjectData.getString("debugTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 5).setCellValue(jsonObjectData.getString("demoProduceTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 6).setCellValue(jsonObjectData.getString("unloaTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 7).setCellValue(jsonObjectData.getString("totalTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 8).setCellValue(jsonObjectData.getString("costTimeRemark"));
            row++;

            /**
             * 异常时间记录
             */
            colorList.add(row);
            PoiUtils.mergedRegion(sheet, row, row, col, col + 8, "二、异常时间记录");
            row++;
            PoiUtils.mergedRegion(sheet, row, row + 1, col, col, "开始~结束时间段（H）");
            PoiUtils.mergedRegion(sheet, row, row + 1, col + 1, col + 1, "时间（H）");
            PoiUtils.mergedRegion(sheet, row, row, col + 2, col + 7, "异常情况描述");
            PoiUtils.mergedRegion(sheet, row + 1, row + 1, col + 2, col + 3, "等待详细内容");
            PoiUtils.mergedRegion(sheet, row + 1, row + 1, col + 4, col + 5, "修模详细内容");
            PoiUtils.mergedRegion(sheet, row + 1, row + 1, col + 6, col + 7, "设备故障内容");
            PoiUtils.mergedRegion(sheet, row, row + 1, col + 8, col + 8, "备注");
            row += 2;
            JSONArray exceptionDataList = jsonObjectData.getJSONArray("exceptionDataList");
            if (Objects.nonNull(exceptionDataList)) {
                for (int i = 0; i < exceptionDataList.size(); i++) {
                    JSONObject exceptionData = (JSONObject) exceptionDataList.get(i);
                    PoiUtils.getRow(sheet, row).createCell(col).setCellValue(exceptionData.getString("exceptionPeriod"));
                    PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue(exceptionData.getString("exceptionHour"));
                    PoiUtils.mergedRegion(sheet, row, row, col + 2, col + 3, exceptionData.getString("waitDetailContent"));
                    PoiUtils.mergedRegion(sheet, row, row, col + 4, col + 5, exceptionData.getString("fixDetialContent"));
                    PoiUtils.mergedRegion(sheet, row, row, col + 6, col + 7, exceptionData.getString("breakdownDetialContent"));
                    PoiUtils.getRow(sheet, row).createCell(col + 8).setCellValue(exceptionData.getString("exceptionRemark"));
                    row++;
                }
            }

            /**
             * 调试及样件生产状态
             */
            colorList.add(row);
            PoiUtils.mergedRegion(sheet, row, row, col, col + 8, "三、调试及样件生产状态");
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue("调试模数");
            PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue("生产模数");
            PoiUtils.getRow(sheet, row).createCell(col + 2).setCellValue("合格品数");
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue("让步接收数");
            PoiUtils.getRow(sheet, row).createCell(col + 4).setCellValue("每模件数");
            PoiUtils.mergedRegion(sheet, row, row, col + 5, col + 6, "单模重量（KG）");
            PoiUtils.mergedRegion(sheet, row, row, col + 7, col + 8, "生产节拍（S）");
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue(jsonObjectData.getString("debugMoldCount"));
            PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue(jsonObjectData.getString("produceMoldCount"));
            PoiUtils.getRow(sheet, row).createCell(col + 2).setCellValue(jsonObjectData.getString("qualifiedMoldCount"));
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue(jsonObjectData.getString("concessionalReceivingCount"));
            PoiUtils.getRow(sheet, row).createCell(col + 4).setCellValue(jsonObjectData.getString("perCount"));
            PoiUtils.mergedRegion(sheet, row, row, col + 5, col + 6, jsonObjectData.getString("moldWeight"));
            PoiUtils.mergedRegion(sheet, row, row, col + 7, col + 8, jsonObjectData.getString("productionTakt"));
            row++;

            /**
             * 消耗材料
             */
            colorList.add(row);
            PoiUtils.mergedRegion(sheet, row, row, col, col + 8, "四、消耗材料");
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue("类别");
            PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue("规格");
            PoiUtils.getRow(sheet, row).createCell(col + 2).setCellValue("计量单位");
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue("领用数");
            PoiUtils.getRow(sheet, row).createCell(col + 4).setCellValue("退库数");
            PoiUtils.getRow(sheet, row).createCell(col + 5).setCellValue("消耗数");
            PoiUtils.mergedRegion(sheet, row, row, col + 6, col + 8, "异常说明");
            row++;
            JSONArray consumableInfoList = jsonObjectData.getJSONArray("consumableInfo");
            if (Objects.nonNull(consumableInfoList)) {
                for (int i = 0; i < consumableInfoList.size(); i++) {
                    JSONObject consumableInfo = (JSONObject) consumableInfoList.get(i);
                    PoiUtils.getRow(sheet, row).createCell(col).setCellValue(consumableInfo.getString("type"));
                    PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue(consumableInfo.getString("specification"));
                    PoiUtils.getRow(sheet, row).createCell(col + 2).setCellValue(consumableInfo.getString("measurement"));
                    PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue(consumableInfo.getString("claim"));
                    PoiUtils.getRow(sheet, row).createCell(col + 4).setCellValue(consumableInfo.getString("stock"));
                    PoiUtils.getRow(sheet, row).createCell(col + 5).setCellValue(consumableInfo.getString("consumption"));
                    PoiUtils.mergedRegion(sheet, row, row, col + 6, col + 8, consumableInfo.getString("description"));
                    row++;
                }
            }

            /**
             * 产品工艺参数
             */
            colorList.add(row);
            PoiUtils.mergedRegion(sheet, row, row, col, col + 8, "五、产品工艺参数");
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue("材料名称/牌号");
            PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue(jsonObjectData.getString("materialName"));
            PoiUtils.getRow(sheet, row).createCell(col + 2).setCellValue("烘料温度");
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue(jsonObjectData.getString("dryingTemperature"));
            PoiUtils.getRow(sheet, row).createCell(col + 4).setCellValue("烘料时间");
            PoiUtils.getRow(sheet, row).createCell(col + 5).setCellValue(jsonObjectData.getString("dryingTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 6).setCellValue("储存终点位置");
            PoiUtils.mergedRegion(sheet, row, row, col + 7, col + 8, jsonObjectData.getString("storageEndPoint"));
            row++;
            PoiUtils.getRow(sheet, row).createCell(col).setCellValue("保压时间");
            PoiUtils.getRow(sheet, row).createCell(col + 1).setCellValue(jsonObjectData.getString("dwellTime"));
            PoiUtils.getRow(sheet, row).createCell(col + 2).setCellValue("保压压力");
            PoiUtils.getRow(sheet, row).createCell(col + 3).setCellValue(jsonObjectData.getString("dwellPressure"));
            PoiUtils.getRow(sheet, row).createCell(col + 4).setCellValue("保压速度");
            PoiUtils.getRow(sheet, row).createCell(col + 5).setCellValue(jsonObjectData.getString("dwellSpeed"));
            PoiUtils.getRow(sheet, row).createCell(col + 6).setCellValue("冷却时间");
            PoiUtils.mergedRegion(sheet, row, row, col + 7, col + 8, jsonObjectData.getString("collingTime"));
            row++;
            PoiUtils.mergedRegion(sheet, row, row + 3, col, col, "射胶参数");
            PoiUtils.mergedRegion(sheet, row, row + 1, col + 1, col + 1, "压力");
            PoiUtils.getRow(sheet, row + 2).createCell(col + 1).setCellValue("速度");
            PoiUtils.getRow(sheet, row + 3).createCell(col + 1).setCellValue("位置");
            JSONArray ejectionEjectionParamsList = jsonObjectData.getJSONArray("ejectionEjectionParams");
            if (Objects.nonNull(ejectionEjectionParamsList)) {
                for (int i = 0; i < ejectionEjectionParamsList.size(); i++) {
                    JSONObject ejectionEjectionParams = (JSONObject) ejectionEjectionParamsList.get(i);
                    int colIndex = col + 2 + i;
                    PoiUtils.getRow(sheet, row).createCell(colIndex).setCellValue(ejectionEjectionParams.getString("ejectionStageName"));
                    PoiUtils.getRow(sheet, row + 1).createCell(colIndex).setCellValue(ejectionEjectionParams.getString("ejectionTempresure"));
                    PoiUtils.getRow(sheet, row + 2).createCell(colIndex).setCellValue(ejectionEjectionParams.getString("ejectionSpeed"));
                    PoiUtils.getRow(sheet, row + 3).createCell(colIndex).setCellValue(ejectionEjectionParams.getString("ejectionposition"));
                }
            }
            PoiUtils.mergedRegion(sheet, row, row + 1, col + 7, col + 7, "模温");
            PoiUtils.mergedRegion(sheet, row, row + 1, col + 8, col + 8, jsonObjectData.getString("moldTemperature"));
            PoiUtils.mergedRegion(sheet, row + 2, row + 3, col + 7, col + 7, "热道流温度");
            PoiUtils.mergedRegion(sheet, row + 2, row + 3, col + 8, col + 8, jsonObjectData.getString("hotRunnerTemperature"));
            row += 4;
            PoiUtils.mergedRegion(sheet, row, row + 1, col, col, "螺杆温度");
            JSONArray screwTemperatureList = jsonObjectData.getJSONArray("screwTemperature");
            if (Objects.nonNull(screwTemperatureList)) {
                int colIndex = col + 1;
                for (int i = 0; i < screwTemperatureList.size(); i++) {
                    JSONObject screwTemperature = (JSONObject) screwTemperatureList.get(i);
                    String stageName = screwTemperature.getString("stageName");
                    String temperatureValue = screwTemperature.getString("temperatureValue");
                    if (i < 2) {
                        colIndex += i;
                        PoiUtils.getRow(sheet, row).createCell(colIndex).setCellValue(stageName);
                        PoiUtils.getRow(sheet, row + 1).createCell(colIndex).setCellValue(temperatureValue);
                    } else {
                        colIndex++;
                        PoiUtils.mergedRegion(sheet, row, row, colIndex, colIndex + 1, stageName);
                        PoiUtils.mergedRegion(sheet, row + 1, row + 1, colIndex, colIndex + 1, temperatureValue);
                        colIndex++;
                    }
                }
            }
            row += 2;
            PoiUtils.mergedRegion(sheet, row, row + 1, col, col, "手画板图片");
            JSONArray imageList = jsonObjectData.getJSONArray("image");
            if (Objects.nonNull(imageList)) {
                for (int i = 0; i < imageList.size(); i++) {
                    String url = imageList.get(i) + "";
                    PoiUtils.cellImage(workbook, sheet, rootUrl + File.separator + url,
                            col + i + 1, row, col + i + 1, row + 1);
                }
            }
            row += 2;

            /**
             * 顺序阀进胶方式
             */
            JSONArray sequentialValveFeedingModeList = jsonObjectData.getJSONArray("sequentialValveFeedingMode");
            log.info("顺序阀进胶方式条数:{}", sequentialValveFeedingModeList.size());
            // 通过加6实现向上取整;每7个显示成一行；一组数据是4行
            int count = (sequentialValveFeedingModeList.size() + 6) / 7;
            int addRow = count * 4 - 1;
            int tempRow = row;
            PoiUtils.mergedRegion(sheet, row, row + addRow, col, col, "顺序阀进胶方式");
            for (int i = 0; i < count; i++) {
                PoiUtils.getRow(sheet, tempRow++).createCell(col + 1).setCellValue("");
                PoiUtils.getRow(sheet, tempRow++).createCell(col + 1).setCellValue("开始");
                PoiUtils.getRow(sheet, tempRow++).createCell(col + 1).setCellValue("结束");
                PoiUtils.getRow(sheet, tempRow++).createCell(col + 1).setCellValue("保压");
            }
            tempRow = row;
            int tempColIndex = col + 2;
            for (int i = 0; i < sequentialValveFeedingModeList.size(); i++) {
                JSONObject sequentialValveFeedingMode = (JSONObject) sequentialValveFeedingModeList.get(i);
                if (tempColIndex % 9 == 0) {
                    tempColIndex = col + 2;
                }
                String number = sequentialValveFeedingMode.getString("number");
                char circleChar = (char) ('\u2460' + (Integer.valueOf(number) - 1));
                PoiUtils.getRow(sheet, tempRow).createCell(tempColIndex).setCellValue(circleChar + "");
                PoiUtils.getRow(sheet, tempRow + 1).createCell(tempColIndex).setCellValue(sequentialValveFeedingMode.getString("start"));
                PoiUtils.getRow(sheet, tempRow + 2).createCell(tempColIndex).setCellValue(sequentialValveFeedingMode.getString("end"));
                PoiUtils.getRow(sheet, tempRow + 3).createCell(tempColIndex).setCellValue(sequentialValveFeedingMode.getString("pressure"));
                if (tempColIndex % 8 == 0) {
                    tempRow += 4;
                }
                tempColIndex++;
            }

            // 设置整个表格的样式
            sheet.forEach(sheetRow -> {
                sheetRow.forEach(cell -> {
                    cell.setCellStyle(createCellStyle(workbook));
                });
                // 设置行高自适应
                sheetRow.setHeight((short) -1);
                // 遍历每个单元格
                for (int colIndex = 0; colIndex < sheetRow.getLastCellNum(); colIndex++) {
                    Cell cell = sheetRow.getCell(colIndex);
                    if (cell != null) {
                        cell.setCellStyle(createCellStyle(workbook));
                        // 计算并设置列宽
                        String cellValue = cell.toString();
                        // 计算宽度，加1个字符的宽度
                        int width = (cellValue.getBytes().length + 1) * 256;
                        sheet.setColumnWidth(colIndex, Math.max(sheet.getColumnWidth(colIndex), width));
                    }
                }
            });
            //特殊样式
            colorList.forEach(index -> {
                PoiUtils.getRow(sheet, index).getCell(0).setCellStyle(specialCellStyle(workbook, true, 11));
            });
            //导出
            PoiUtils.createExcelFile(workbook, filePath, fileName);
        } catch (Exception e) {
            e.printStackTrace();
        }


        log.info("试模报告单导出成功");
        return JSON.toJSONString(R.data("文件路径 filePath: " + resultPath));
    }

    /**
     * 设置单元格样式
     */
    private XSSFCellStyle createCellStyle(XSSFWorkbook workbook) {
        XSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //加边框
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);
        cellStyle.setFillForegroundColor((short) 9);
        cellStyle.setWrapText(true);
        XSSFFont font = workbook.createFont();
        //设置字体名称
        font.setFontName("宋体");
        font.setFontHeightInPoints((short) 11);
        //设置字体颜色
        font.setColor(IndexedColors.BLACK1.index);
        cellStyle.setFont(font);

        return cellStyle;
    }

    /**
     * 特殊样式
     *
     * @param workbook
     * @return
     */
    private XSSFCellStyle specialCellStyle(XSSFWorkbook workbook, boolean isForeground, int fontSize) {
        XSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setWrapText(true);
        //加边框
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);
        if (isForeground) {
            //自定义颜色对象
            cellStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(232, 235, 247), new DefaultIndexedColorMap()));
        } else {
            cellStyle.setFillForegroundColor((short) 9);
        }

        XSSFFont font = workbook.createFont();
        //设置字体名称
        font.setFontName("宋体");
        font.setBold(true);
        font.setFontHeightInPoints((short) fontSize);
        //设置字体颜色
        font.setColor(IndexedColors.BLACK1.index);
        cellStyle.setFont(font);

        return cellStyle;
    }


    @Override
    public String getTryOutRecord(JSONObject jsonObject, HttpServletRequest request) {
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");

        SystemHeader header = MyUtils.getHeader(request);
        TestNoticeMainTabale mainTabale = testNoticeMainTabaleMapper.selectById(noteId);
        if (ObjectUtil.isNotNull(mainTabale)) {
            //审批验证
            if (MyUtils.verifyNotice(1, mainTabale.getStatus())) {
                return JSON.toJSONString(R.fail(500, NoticeMainEnum.getMessage(mainTabale.getStatus())));
            }
        } else {
            return JSON.toJSONString(R.success("无数据"));
        }

        TestNoticeTimeTable timeTable = testNoticeTimeTableMapper.selectOne(
                new QueryWrapper<TestNoticeTimeTable>()
                        .lambda()
                        .eq(TestNoticeTimeTable::getParentNoticeId, noteId)
        );
        if (ObjectUtil.isNotNull(timeTable)) {
            JSONObject json = new JSONObject();
            json.put("reachedTime", MyUtils.getLocalDataTimeByString(timeTable.getReachedTime()));
            //时间封装
            String[] str = {"loadTimes", "waitTimes", "demoProduceTimes", "unloadTimes", "breakdownTimes", "fixTimes", "debugTimes"};
            for (int i = 0; i < str.length; i++) {
                json.put(str[i], NoticeTimeUtil.getTimeArray(
                        testNoticeTimeService.list(new LambdaQueryWrapper<TestNoticeTime>()
                                .eq(TestNoticeTime::getParentNoticeId, noteId)
                                .eq(TestNoticeTime::getStatus, i + 1)
                                .orderByAsc(TestNoticeTime::getSort)),
                        i + 1));
            }
            return JSON.toJSONString(R.data(json));
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String getTryOutRecordList(JSONObject jsonObject) {
        //jsonobject解析获取项目负责人
        String username = jsonObject.getString("username");
        //jsonobject解析获取模具名称
        String moldName = jsonObject.getString("moldName");
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        //jsonobject解析获取页码
        Long pageNum = jsonObject.getLong("pageNum");
        //jsonobject解析获取每页数量
        Long pageSize = jsonObject.getLong("pageSize");
        //jsonobject解析获取模具编号
        String moldId = jsonObject.getString("moldId");
        //jsonobject解析获取通知单名称
        String noteName = jsonObject.getString("noteName");
        String deviceId = jsonObject.getString("deviceId");
        String T0Time = jsonObject.getString("T0Time");
        String tryoutStatus = jsonObject.getString("tryoutStatus");
        String tongName = jsonObject.getString("tongName");
        String projectName = jsonObject.getString("projectName");
        String T0TimeStart = null;
        String T0TimeEnd = null;
        if (StringUtils.isNotBlank(T0Time)) {
            T0TimeStart = T0Time + " 00:00:00";
            T0TimeEnd = T0Time + " 23:59:59";
        }
        List<String> list = null;
        if (StringUtils.isNotBlank(tryoutStatus)) {
            list = new ArrayList<>();
            if ("0".equals(tryoutStatus)) {
                list.add("1");
                list.add("2");
                list.add("3");
                list.add("8");
            } else {
                list.add("4");
            }
        }
        List<String> tn = null;
        if (StringUtils.isNotBlank(tongName)) {
            List<OaUserParam> params = oaUserService.lambdaQuery().like(OaUserParam::getName, tongName).list();
            if (CollectionUtil.isNotEmpty(params)) {
                tn = new ArrayList<>();
                for (OaUserParam param : params) {
                    tn.add(param.getId() + "");
                }
            }
        }
        Page<Map<String, Object>> page = new Page<>(pageNum, pageSize);
        IPage<Map<String, Object>> recordPage = testNoticeTimeTableMapper
                .getTryOutRecordPage(
                        page,
                        username,
                        noteId,
                        moldId,
                        moldName,
                        noteName,
                        deviceId,
                        T0TimeStart,
                        T0TimeEnd,
                        list,
                        tn,
                        projectName
                );
        if (CollectionUtil.isNotEmpty(recordPage.getRecords())) {
            Map<String, Object> resultMap = new HashMap<>();
            JSONArray array = new JSONArray();
            JSONObject json;
            for (Map<String, Object> record : recordPage.getRecords()) {
                json = new JSONObject();
                json.put("noteId", record.get("id"));
                json.put("projectName", ObjectUtil.isNull(record.get("project_name")) ? ObjectUtil.isNull(record.get("projectName")) ? "" : record.get("projectName") : record.get("project_name"));
                json.put("moldId", ObjectUtil.isNull(record.get("mold_id")) ? "" : record.get("mold_id"));
                json.put("moldName", ObjectUtil.isNull(record.get("mold_name")) ? "" : record.get("mold_name"));
                json.put("projectManagerName", ObjectUtil.isNull(record.get("project_manager")) ? "" : record.get("project_manager"));
                json.put("noteName", ObjectUtil.isNotEmpty(record.get("note_name")) ? record.get("note_name") : record.get("mold_name") + "_T" + record.get("try_out_times") + "_" + "试模通知单");
                if (ObjectUtil.isEmpty(record.get("note_name"))) {
                    if (ObjectUtil.isNotEmpty(record.get("mold_name")) && ObjectUtil.isNotEmpty(record.get("try_out_times"))) {
                        String noteNames = record.get("mold_name") + "_T" + record.get("try_out_times") + "_" + "试模通知单";
                        LambdaUpdateWrapper<TestNoticeMainTabale> wrapper = new LambdaUpdateWrapper<>();
                        wrapper.set(TestNoticeMainTabale::getNoteName, noteNames);
                        wrapper.eq(TestNoticeMainTabale::getId, record.get("id"));
                        testNoticeMainTabaleMapper.update(null, wrapper);
                    }
                }
                json.put("recordCount", "T" + (ObjectUtil.isNull(record.get("try_out_times")) ? "" : record.get("try_out_times")));
                json.put("tongmanNameName", oaUserService.getOaUserName(record.get("tongman_name").toString()));
                json.put("status", NoticeMainEnum.getMessageName(MyUtils.getObjectString(record.get("status"))));
                json.put("tryoutStatus", NoticeMainEnum.getMessageValue(record.get("status").toString()));
                json.put("edition", "V" + (ObjectUtil.isNotEmpty(record.get("edition_notice")) ? record.get("edition_notice").toString() : "1"));
                json.put("userId", MyUtils.objGetString(record.get("reportId")));
                array.add(json);
            }
            resultMap.put("datas", array);
            resultMap.put("total", recordPage.getTotal());
            return JSON.toJSONString(R.data(resultMap));
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String addTryOutRecord(JSONObject jsonObject, HttpServletRequest request) {
        //jsonobject解析获取模具到达时间
        String reachedTime = jsonObject.getString("reachedTime");
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        //jsonobject解析是否完成试模
        Boolean isDone = jsonObject.getBoolean("isDone");
        TestNoticeMainTabale mainTabale = testNoticeMainTabaleMapper.selectById(noteId);
        if (ObjectUtil.isNull(mainTabale)) {
            return JSON.toJSONString(R.fail("试模通知单不存在/已删除"));
        }
        //审批验证
        if (MyUtils.verifyNotice(1, mainTabale.getStatus())) {
            return JSON.toJSONString(R.fail(500, NoticeMainEnum.getMessage(mainTabale.getStatus())));
        }
        int parseInt = Integer.parseInt(mainTabale.getStatus());
        if (parseInt > 2 && parseInt != 8) {
            return JSON.toJSONString(R.fail("已完成开始试模阶段，不可修改"));
        }
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        TestNoticeTimeTable timeTable = getOne(
                new QueryWrapper<TestNoticeTimeTable>()
                        .lambda()
                        .eq(TestNoticeTimeTable::getParentNoticeId, noteId)
        );
        if (ObjectUtil.isNull(timeTable)) {
            timeTable = new TestNoticeTimeTable();
        }
        timeTable.setParentNoticeId(noteId);
        if (StringUtils.isNotBlank(reachedTime)) {
            timeTable.setReachedTime(reachedTime);
        }
        if (ObjectUtil.isNotEmpty(isDone) && isDone) {
            //修改通知单试模状态
            mainTabale.setStatus(NoticeMainEnum.END_MOLD_TIME.getCode());
            testNoticeMainTabaleMapper.updateById(mainTabale);
        } else {
            SystemHeader header = MyUtils.getHeader(request);
            mainTabale.setTongmanName(header.getId());
            mainTabale.setStatus(NoticeMainEnum.START_MOLD_TIME.getCode());
            testNoticeMainTabaleMapper.updateById(mainTabale);
        }

        //保存时间
        JSONArray loadTimes = jsonObject.getJSONArray("loadTimes");
        JSONArray waitTimes = jsonObject.getJSONArray("waitTimes");
        JSONArray demoProduceTimes = jsonObject.getJSONArray("demoProduceTimes");
        JSONArray unloadTimes = jsonObject.getJSONArray("unloadTimes");
        JSONArray breakdownTimes = jsonObject.getJSONArray("breakdownTimes");
        JSONArray fixTimes = jsonObject.getJSONArray("fixTimes");
        JSONArray debugTimes = jsonObject.getJSONArray("debugTimes");
        List<TestNoticeTime> times = Lists.newArrayList();
        try {
            if (CollectionUtil.isNotEmpty(loadTimes)) {
                times = NoticeTimeUtil.getTimes(times, loadTimes, 1, timeTable.getParentNoticeId());
            }
            if (CollectionUtil.isNotEmpty(waitTimes)) {
                times = NoticeTimeUtil.getTimes(times, waitTimes, 2, timeTable.getParentNoticeId());
            }
            if (CollectionUtil.isNotEmpty(demoProduceTimes)) {
                times = NoticeTimeUtil.getTimes(times, demoProduceTimes, 3, timeTable.getParentNoticeId());
            }
            if (CollectionUtil.isNotEmpty(unloadTimes)) {
                times = NoticeTimeUtil.getTimes(times, unloadTimes, 4, timeTable.getParentNoticeId());
            }
            if (CollectionUtil.isNotEmpty(breakdownTimes)) {
                times = NoticeTimeUtil.getTimes(times, breakdownTimes, 5, timeTable.getParentNoticeId());
            }
            if (CollectionUtil.isNotEmpty(fixTimes)) {
                times = NoticeTimeUtil.getTimes(times, fixTimes, 6, timeTable.getParentNoticeId());
            }
            if (CollectionUtil.isNotEmpty(debugTimes)) {
                times = NoticeTimeUtil.getTimes(times, debugTimes, 7, timeTable.getParentNoticeId());
            }
        } catch (Exception e) {
            log.error("保存试模记录接口发生错误:{}", e.toString(), e);
            return JSON.toJSONString(R.fail(500, "试模的用时时间,结束时间不应小于/等于开始时间"));
        }
        testNoticeTimeService.remove(new LambdaQueryWrapper<TestNoticeTime>().eq(TestNoticeTime::getParentNoticeId, timeTable.getParentNoticeId()));
        testNoticeTimeService.saveBatch(times);
        saveOrUpdate(timeTable);
        return JSON.toJSONString(R.success("保存成功"));
    }

    private List<String> verityDict(String baseId, String updateId) {
        String baseValue = "";
        String updateValue = "";
        DictTable dictType = dictTableMapper.selectById(baseId);
        if (ObjectUtil.isNotNull(dictType)) {
            baseValue = dictType.getDicName();
        }
        DictTable dictType1 = dictTableMapper.selectById(updateId);
        if (ObjectUtil.isNotNull(dictType1)) {
            updateValue = dictType1.getDicName();
        }
        return Arrays.asList(baseValue, updateValue);
    }

    @Override
    @Transactional
    public synchronized String addTryOutReport(JSONObject jsonObject, HttpServletRequest request) {
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        //jsonobject解析获取名称
        String reportName = jsonObject.getString("reportName");
        //jsonobject解析获取编号
        String serialNumber = jsonObject.getString("serialNumber");
        //jsonobject解析获取版本Id
        String versionId = jsonObject.getString("versionId");
        //jsonobject解析获取试模日期
        String tryOutDate = jsonObject.getString("tryOutDate");
        //jsonobject解析获取项目名称
        String projectName = jsonObject.getString("projectName");
        //jsonobject解析获取模具编号
        String moldId = jsonObject.getString("moldId");
        //jsonobject解析获取试模设备
        String tryOutDeviceId = jsonObject.getString("tryOutDeviceId");
        //jsonobject解析获取试模次数
        String tryOutTimes = jsonObject.getString("tryOutTimes");
        //jsonobject解析获取试模类型Id
        String tryOutTypeId = jsonObject.getString("tryOutTypeId");
        //jsonobject解析获取试模单位Id
        String tryOutCompanyId = jsonObject.getString("tryOutCompanyId");
        //jsonobject解析获取试模调试工程师
        String tryOutEngineer = jsonObject.getString("tryOutEngineer");
        //jsonobject解析获取项目工程师
        String projectManager = jsonObject.getString("projectManager");
        //jsonobject解析获取上模等待用时（H）
        String loadTime = jsonObject.getString("loadTime");
        //jsonobject解析获取等待总时数（H）
        String waitTime = jsonObject.getString("waitTime");
        //jsonobject解析获取设备故障用时（H）
        String breakdownTime = jsonObject.getString("breakdownTime");
        //jsonobject解析获取修模用时（H）
        String fixTime = jsonObject.getString("fixTime");
        //jsonobject解析获取调试用时（H）
        String debugTime = jsonObject.getString("debugTime");
        //jsonobject解析获取样件生产时间（H）
        String demoProduceTime = jsonObject.getString("demoProduceTime");
        //jsonobject解析获取下模时间（H)
        String unloaTime = jsonObject.getString("unloaTime");
        //jsonobject解析获取当天合计用时总数(H)
        String totalTime = jsonObject.getString("totalTime");
        //jsonobject解析获取用时记录备注
        String costTimeRemark = jsonObject.getString("costTimeRemark");
        //jsonobject解析获取开始结束时间段（H）
        String exceptionPeriod = jsonObject.getString("exceptionPeriod");
        //jsonobject解析获取时间（H）
        String exceptionHour = jsonObject.getString("exceptionHour");
        //jsonobject解析获取等待详细内容
        String waitDetailContent = jsonObject.getString("waitDetailContent");
        //jsonobject解析获取修模详细内容
        String fixDetialContent = jsonObject.getString("fixDetialContent");
        //jsonobject解析获取设备故障内容
        String breakdownDetialContent = jsonObject.getString("breakdownDetialContent");
        //jsonobject解析获取异常时间记录备注
        String exceptionRemark = jsonObject.getString("exceptionRemark");
        //jsonobject解析获取调试模数
        String debugMoldCount = jsonObject.getString("debugMoldCount");
        //jsonobject解析获取生产模数
        String produceMoldCount = jsonObject.getString("produceMoldCount");
        //jsonobject解析获取合格品数
        String qualifiedMoldCount = jsonObject.getString("qualifiedMoldCount");
        //jsonobject解析获取让步接收数
        String concessionalReceivingCount = jsonObject.getString("concessionalReceivingCount");
        //jsonobject解析获取每模件数
        String perCount = jsonObject.getString("perCount");
        //jsonobject解析获取单模重量（KG)
        String moldWeight = jsonObject.getString("moldWeight");
        //jsonobject解析获取生产节拍（S)
        String productionTakt = jsonObject.getString("productionTakt");
        //jsonobject解析获取材料名称/牌号
        String materialName = jsonObject.getString("materialName");
        //jsonobject解析获取烘料温度
        String dryingTemperature = jsonObject.getString("dryingTemperature");
        //jsonobject解析获取烘料时间
        String dryingTime = jsonObject.getString("dryingTime");
        //jsonobject解析获取储料终点位置
        String storageEndPoint = jsonObject.getString("storageEndPoint");
        //jsonobject解析获取保压时间
        String dwellTime = jsonObject.getString("dwellTime");
        //jsonobject解析获取保压压力
        String dwellPressure = jsonObject.getString("dwellPressure");
        //jsonobject解析获取保压速度
        String dwellSpeed = jsonObject.getString("dwellSpeed");
        //jsonobject解析获取冷却时间
        String collingTime = jsonObject.getString("collingTime");
        //jsonobject解析获取模温
        String moldTemperature = jsonObject.getString("moldTemperature");
        //jsonobject解析获取热流道温度
        String hotRunnerTemperature = jsonObject.getString("hotRunnerTemperature");
        //jsonobject解析获取射胶参数对象数组) Ejectio
        JSONArray ejectionEjectionParams = jsonObject.getJSONArray("ejectionEjectionParams");
        //jsonobject解析获取螺杆温度
        JSONArray screwTemperature = jsonObject.getJSONArray("screwTemperature");
        //jsonobject解析获取顺序阀进胶方式
        JSONArray sequentialValveFeedingMode = jsonObject.getJSONArray("sequentialValveFeedingMode");
        //jsonobject解析获取异常时间记录数组
        JSONArray exceptionDataList = jsonObject.getJSONArray("exceptionDataList");
        //jsonobject解析获取耗材信息
        JSONArray consumableInfoList = jsonObject.getJSONArray("consumableInfo");
        //jsonobject解析获取手画板图片
        List<String> imageList = null;
        if (jsonObject.containsKey("image") && Objects.nonNull(jsonObject.getJSONArray("image")) && jsonObject.getJSONArray("image").size() > 0) {
            JSONArray imageArray = jsonObject.getJSONArray("image");
            imageList = JSONObject.parseArray(imageArray.toJSONString(), String.class);
        }
        TestNoticeMainTabale mainTabale = testNoticeMainTabaleMapper.selectById(noteId);
        if (ObjectUtil.isNotNull(mainTabale)) {
            //用户信息
            SystemHeader header = MyUtils.getHeader(request);
            if (null == mainTabale.getReportId()) {
                mainTabale.setReportId(header.getId());
            } else if (!mainTabale.getReportId().equals(header.getId())) {
                return JSON.toJSONString(R.fail("该报告不属于您，暂无权限修改"));
            }
            //审批验证
            if (MyUtils.verifyNotice(1, mainTabale.getStatus())) {
                return JSON.toJSONString(R.fail(500, NoticeMainEnum.getMessage(mainTabale.getStatus())));
            }
            if (mainTabale.getStatus().equals(NoticeMainEnum.SUBMITTED.getCode())) {
                return JSON.toJSONString(R.success("表单已提交，不可修改"));
            }
            TestModelSubTable subTable = testModelSubTableMapper.selectById(mainTabale.getParentPlanSubId());
            //版次
            if (null == mainTabale.getEditionNotice()) {
                mainTabale.setEditionNotice(1);
            }
            String times = "T";
            Integer version = mainTabale.getEditionNotice();
            List<EdtionNotice> list = new ArrayList<>();
            List<EdtionNotice> mainEdition = EdtionVerity.veriryTestNoticeMain(
                    noteId,
                    version + 1,
                    header.getId(),
                    projectName,
                    reportName,
                    StringUtils.isNotBlank(tryOutTypeId) && !tryOutTypeId.equals(mainTabale.getTryOutTypeId()) ? verityDict(mainTabale.getTryOutTypeId(), tryOutTypeId) : null,
                    StringUtils.isNotBlank(tryOutCompanyId) && !tryOutCompanyId.equals(mainTabale.getTryOutCompanyId()) ? verityDict(mainTabale.getTryOutCompanyId(), tryOutCompanyId) : null,
                    StringUtils.isNotBlank(tryOutDeviceId) && !tryOutDeviceId.equals(mainTabale.getTryOutDeviceId()) ? verityDict(mainTabale.getTryOutDeviceId(), tryOutDeviceId) : null,
                    StringUtils.isNotBlank(versionId) && !versionId.equals(mainTabale.getTestVersionId()) ? verityDict(mainTabale.getTestVersionId(), versionId) : null,
                    times + subTable.getTryOutTimes(),
                    tryOutTimes,
                    mainTabale
            );
            if (CollectionUtil.isNotEmpty(mainEdition)) {
                list.addAll(mainEdition);
            }
            //修改表单状态

            mainTabale.setTestVersionId(versionId);
            mainTabale.setProjectName(projectName);
            mainTabale.setReportName(reportName);
            mainTabale.setTryOutTypeId(tryOutTypeId);
            mainTabale.setTryOutCompanyId(tryOutCompanyId);
            mainTabale.setTryOutDeviceId(tryOutDeviceId);
            mainTabale.setStatus(NoticeMainEnum.TEST_MOLD_REPORT.getCode());

            if (StringUtils.isNotEmpty(tryOutTimes) && tryOutTimes.toUpperCase().contains(times)) {
                if (StringUtils.isNumeric(tryOutTimes.toUpperCase().split(times)[1])) {
                    subTable.setTryOutTimes(tryOutTimes.toUpperCase().split(times)[1]);
                }
            }
            if (StringUtils.isNotBlank(tryOutDate)) {
                subTable.setPracticalTime(MyUtils.stringToDate(tryOutDate));
            }
            testModelSubTableMapper.updateById(subTable);
            //一、试模用时记录
            TestNoticeTimeTable timeTable = testNoticeTimeTableMapper
                    .selectOne(
                            new QueryWrapper<TestNoticeTimeTable>()
                                    .lambda()
                                    .eq(TestNoticeTimeTable::getParentNoticeId, noteId)
                    );
            if (ObjectUtil.isNotNull(timeTable)) {
                if (null != costTimeRemark && costTimeRemark.equals(timeTable.getRemark())) {
                    EdtionNotice edtion = new EdtionNotice();
                    edtion.setRed_id(noteId);
                    edtion.setEdition("V" + (version + 1));
                    edtion.setKeyName("costTimeRemark");
                    edtion.setKeyValue("用时记录备注");
                    edtion.setBaseValue(timeTable.getRemark());
                    edtion.setUpdateValue(costTimeRemark);
                    edtion.setPerson(header.getId());
                    list.add(edtion);
                }
                timeTable.setRemark(costTimeRemark);
                testNoticeTimeTableMapper.updateById(timeTable);
            }
            //二、异常时间记录
            if (CollectionUtil.isNotEmpty(exceptionDataList)) {
                List<LinkedHashMap> jsonObjectList = exceptionDataList.toJavaList(LinkedHashMap.class);
                for (LinkedHashMap object : jsonObjectList) {
                    String exceptionId = MyUtils.getObjectString(object.get("exceptionId"));
                    TestNoticeExceptionTimeTable exceptionTimeTable = new TestNoticeExceptionTimeTable();
                    exceptionTimeTable.setParentNoticeId(noteId);
                    exceptionTimeTable.setTimeFrame(MyUtils.getObjectString(object.get("exceptionPeriod")));
                    exceptionTimeTable.setTimes(MyUtils.getObjectString(object.get("exceptionHour")));
                    exceptionTimeTable.setWaitContent(MyUtils.getObjectString(object.get("waitDetailContent")));
                    exceptionTimeTable.setRepairContent(MyUtils.getObjectString(object.get("fixDetialContent")));
                    exceptionTimeTable.setFaultContent(MyUtils.getObjectString(object.get("breakdownDetialContent")));
                    exceptionTimeTable.setRemark(MyUtils.getObjectString(object.get("exceptionRemark")));
                    if (StringUtils.isBlank(exceptionId) || exceptionId.equals("0")) {
                        String toString = exceptionTimeTable.toString();
                        if (StringUtils.isNotBlank(toString)) {
                            EdtionNotice edtion = new EdtionNotice();
                            edtion.setRed_id(noteId);
                            edtion.setEdition("V" + (version + 1));
                            edtion.setKeyValue("新增");
                            edtion.setUpdateValue(exceptionTimeTable.toString());
                            edtion.setPerson(header.getId());
                            list.add(edtion);
                        }
                        testNoticeExceptionTimeTableMapper.insert(exceptionTimeTable);
                    } else {
                        TestNoticeExceptionTimeTable oldException = testNoticeExceptionTimeTableMapper.selectById(exceptionId);
                        if (ObjectUtil.isNotNull(oldException)) {
                            List<EdtionNotice> exception = EdtionVerity.veriryException(noteId, version + 1, header.getId(), oldException, exceptionTimeTable);
                            if (CollectionUtil.isNotEmpty(exception)) {
                                list.addAll(exception);
                            }
                            exceptionTimeTable.setExceptionId(oldException.getExceptionId());
                            testNoticeExceptionTimeTableMapper.updateById(exceptionTimeTable);
                        }
                    }

                }
            }
            //三、调试及样件生产状态
            TestNoticeProductionTypeTable productionTypeTable = new TestNoticeProductionTypeTable();
            productionTypeTable.setParentNoticeId(noteId);
            productionTypeTable.setModulusQuantity(debugMoldCount);
            productionTypeTable.setProductionQuantity(produceMoldCount);
            productionTypeTable.setQualifiedQuantity(qualifiedMoldCount);
            productionTypeTable.setReceiveQuantity(concessionalReceivingCount);
            productionTypeTable.setMoldNumber(perCount);
            productionTypeTable.setModelWeight(moldWeight);
            productionTypeTable.setProductionBeat(productionTakt);
            TestNoticeProductionTypeTable oldProduction = testNoticeProductionTypeTableMapper.selectOne(new LambdaQueryWrapper<TestNoticeProductionTypeTable>()
                    .eq(TestNoticeProductionTypeTable::getParentNoticeId, noteId).last("LIMIT 1"));
            if (ObjectUtil.isNotNull(oldProduction)) {
                productionTypeTable.setDebugId(oldProduction.getDebugId());
                testNoticeProductionTypeTableMapper.updateById(productionTypeTable);
                List<EdtionNotice> production = EdtionVerity.veriryProduction(noteId, version + 1, header.getId(), oldProduction, productionTypeTable);
                if (CollectionUtil.isNotEmpty(production)) {
                    list.addAll(production);
                }
            } else {
                String toString = productionTypeTable.toString();
                if (StringUtils.isNotBlank(toString)) {
                    EdtionNotice edtion = new EdtionNotice();
                    edtion.setRed_id(noteId);
                    edtion.setEdition("V" + (version + 1));
                    edtion.setKeyValue("新增");
                    edtion.setUpdateValue(toString);
                    edtion.setPerson(header.getId());
                    list.add(edtion);
                }
                testNoticeProductionTypeTableMapper.insert(productionTypeTable);
            }
            //四、消耗材料
            LambdaQueryWrapper<TestNoticeConsumableTable> queryWrapper = new QueryWrapper<TestNoticeConsumableTable>().lambda()
                    .eq(TestNoticeConsumableTable::getParentNoticeId, noteId);
            List<TestNoticeConsumableTable> testNoticeConsumableTableList = testNoticeConsumableTableMapper.selectList(queryWrapper);
            log.info("页面耗材:{}", consumableInfoList.toJSONString());
            log.info("db耗材:{}", JSONObject.toJSONString(testNoticeConsumableTableList));
            if (Objects.nonNull(consumableInfoList) && consumableInfoList.size() > 0) {
                List<TestNoticeConsumableTable> testNoticeConsumableTableParamList = JSONObject.parseArray(consumableInfoList.toJSONString(), TestNoticeConsumableTable.class);
                //旧数据，新数据获取交集 ---> 编辑的耗材
                List<TestNoticeConsumableTable> updateTestNoticeConsumableTableList = testNoticeConsumableTableParamList.stream()
                        .filter(item1 -> testNoticeConsumableTableList.stream()
                                .anyMatch(item2 -> item1.isEqualTo(item2)))
                        .collect(Collectors.toList());
                //获取删除的耗材
                List<TestNoticeConsumableTable> delTestNoticeConsumableTableList = testNoticeConsumableTableList.stream()
                        .filter(item2 -> updateTestNoticeConsumableTableList.stream()
                                .noneMatch(item1 -> item1.isEqualTo(item2)))
                        .collect(Collectors.toList());
                //获取新增的耗材
                List<TestNoticeConsumableTable> addTestNoticeConsumableTableList = testNoticeConsumableTableParamList.stream()
                        .filter(item2 -> updateTestNoticeConsumableTableList.stream()
                                .noneMatch(item1 -> item1.isEqualTo(item2)))
                        .collect(Collectors.toList());
                log.info("编辑的耗材：{}", JSONObject.toJSONString(updateTestNoticeConsumableTableList));
                if (updateTestNoticeConsumableTableList.size() > 0) {
                    Map<String, TestNoticeConsumableTable> newTestNoticeConsumableTableMap = testNoticeConsumableTableParamList.parallelStream().collect(Collectors.toMap(testNoticeConsumableTable -> testNoticeConsumableTable.getType() + "-" + testNoticeConsumableTable.getSpecification(), Function.identity()));
                    Map<String, TestNoticeConsumableTable> oldTestNoticeConsumableTableMap = testNoticeConsumableTableList.parallelStream().collect(Collectors.toMap(testNoticeConsumableTable -> testNoticeConsumableTable.getType() + "-" + testNoticeConsumableTable.getSpecification(), Function.identity()));
                    updateTestNoticeConsumableTableList.forEach(testNoticeConsumableTable -> {
                        String key = testNoticeConsumableTable.getType() + "-" + testNoticeConsumableTable.getSpecification();
                        TestNoticeConsumableTable newTestNoticeConsumableTable = newTestNoticeConsumableTableMap.get(key);
                        TestNoticeConsumableTable oldTestNoticeConsumableTable = oldTestNoticeConsumableTableMap.get(key);
                        List<EdtionNotice> consumable = EdtionVerity.veriryConsumable(noteId, version + 1, header.getId(), oldTestNoticeConsumableTable, newTestNoticeConsumableTable);
                        list.addAll(consumable);
                    });
                }
                log.info("删除的耗材：{}", JSONObject.toJSONString(delTestNoticeConsumableTableList));
                if (delTestNoticeConsumableTableList.size() > 0) {
                    delTestNoticeConsumableTableList.forEach(testNoticeConsumableTable -> {
                        List<EdtionNotice> consumable = EdtionVerity.veriryConsumable(noteId, version + 1, header.getId(), testNoticeConsumableTable, null);
                        list.addAll(consumable);
                    });
                }
                log.info("新增的耗材：{}", JSONObject.toJSONString(addTestNoticeConsumableTableList));
                if (addTestNoticeConsumableTableList.size() > 0) {
                    addTestNoticeConsumableTableList.forEach(testNoticeConsumableTable -> {
                        List<EdtionNotice> consumable = EdtionVerity.veriryConsumable(noteId, version + 1, header.getId(), null, testNoticeConsumableTable);
                        list.addAll(consumable);
                    });
                }
                testNoticeConsumableTableMapper.delete(queryWrapper);
                List<TestNoticeConsumableTable> dataList = testNoticeConsumableTableParamList.stream().map(testNoticeConsumableTable -> {
                    testNoticeConsumableTable.setParentNoticeId(noteId);
                    return testNoticeConsumableTable;
                }).collect(Collectors.toList());
                testNoticeConsumableTableService.saveBatch(dataList);
            } else {
                log.info("删除全部耗材");
                testNoticeConsumableTableMapper.delete(queryWrapper);
                testNoticeConsumableTableList.forEach(testNoticeConsumableTable -> {
                    List<EdtionNotice> consumable = EdtionVerity.veriryConsumable(noteId, version + 1, header.getId(), testNoticeConsumableTable, null);
                    list.addAll(consumable);
                });
            }
            //五、产品工艺参数
            TestNoticeProductionProcessTable oldProcessTable = testNoticeProductionProcessTableMapper.selectOne(
                    new QueryWrapper<TestNoticeProductionProcessTable>()
                            .lambda()
                            .eq(TestNoticeProductionProcessTable::getParentNoticeId, noteId)
                            .last("LIMIT 1")
            );
            TestNoticeProductionProcessTable productionProcessTable = new TestNoticeProductionProcessTable();
            productionProcessTable.setParentNoticeId(noteId);
            productionProcessTable.setMaterialName(materialName);
            productionProcessTable.setBakingTemperature(dryingTemperature);
            productionProcessTable.setBakingTime(dryingTime);
            productionProcessTable.setEndPosition(storageEndPoint);
            productionProcessTable.setHoldingTime(dwellTime);
            productionProcessTable.setHoldingPressure(dwellPressure);
            productionProcessTable.setHoldingSpeed(dwellSpeed);
            productionProcessTable.setCoolingTime(collingTime);
            productionProcessTable.setSprue(ejectionEjectionParams.toJSONString());
            productionProcessTable.setScrewTemperature(screwTemperature.toJSONString());
            productionProcessTable.setMoldTemperature(moldTemperature);
            productionProcessTable.setHeatedTemperature(hotRunnerTemperature);
            productionProcessTable.setSprueFeedingMethod(sequentialValveFeedingMode.toJSONString());
            //productionProcessTable.setImage(image);
            EdtionVerity.verityConsumable(
                    noteId,
                    version + 1,
                    header.getId(),
                    oldProcessTable,
                    productionProcessTable,
                    list
            );
            if (CollectionUtil.isNotEmpty(list)) {
                edtionNoticeService.saveBatch(list);
                mainTabale.setEditionNotice(mainTabale.getEditionNotice() + 1);
            }
            // 1
            testNoticeMainTabaleMapper.updateById(mainTabale);
            // 5
            if (ObjectUtil.isNotNull(oldProcessTable)) {
                productionProcessTable.setProductionId(oldProcessTable.getProductionId());
                testNoticeProductionProcessTableMapper.updateById(productionProcessTable);
            } else {
                testNoticeProductionProcessTableMapper.insert(productionProcessTable);
            }
            //保存图片
            testImageMapper.delete(new LambdaUpdateWrapper<TestImage>().eq(TestImage::getType, 1).eq(TestImage::getSceneId, productionProcessTable.getProductionId()));
            if (Objects.nonNull(imageList) && !imageList.isEmpty()) {
                List<TestImage> testImageList = imageList.stream().map(url -> {
                            TestImage testImage = new TestImage();
                            testImage.setType(1);
                            testImage.setSceneId(productionProcessTable.getProductionId());
                            testImage.setUrl(url);
                            return testImage;
                        })
                        .collect(Collectors.toList());
                testImageService.saveBatch(testImageList);
            }

            return JSON.toJSONString(R.success("保存成功"));
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String postTryOutReport(JSONObject jsonObject, HttpServletRequest request) {
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        TestNoticeMainTabale mainTabale = testNoticeMainTabaleMapper.selectById(noteId);
        if (ObjectUtil.isNotNull(mainTabale)) {
            //用户信息
            SystemHeader header = MyUtils.getHeader(request);
            if (!mainTabale.getReportId().equals(header.getId())) {
                return JSON.toJSONString(R.fail("该报告不属于您，暂无权限提交"));
            }
            //审批验证
            if (MyUtils.verifyNotice(1, mainTabale.getStatus())) {
                return JSON.toJSONString(R.fail(500, NoticeMainEnum.getMessage(mainTabale.getStatus())));
            }
            mainTabale.setStatus(NoticeMainEnum.SUBMITTED.getCode());
            mainTabale.setUpdateTime(new Date());
            testNoticeMainTabaleMapper.updateById(mainTabale);
            return JSON.toJSONString(R.success("提交成功"));
        }
        return JSON.toJSONString(R.success("无数据"));
    }

}
